package com.tensquare.friend.controller;

import com.tensquare.common.auth.annotation.Authority;
import com.tensquare.common.auth.constant.AuthorityCode;
import com.tensquare.friend.service.FriendService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tensquare.common.util.SecurityUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: WangYaWei
 * @description:
 * @create: 2019-08-26 17:09
 **/
@RestController
@RequestMapping(value = "/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private SecurityUtils securityUtils;

    @Authority(AuthorityCode.USER)
    @PutMapping(value = "/like/{friendid}/{type}")
    public Result addFriend(@PathVariable String friendid, @PathVariable String type){
        if("1".equals(type)){
            //喜欢添加
            friendService.addFriend((String) securityUtils.getCuurentUserid(), friendid);
        }else{
            //不喜欢
            friendService.addNoFriend((String) securityUtils.getCuurentUserid(), friendid);
        }
        return new Result(true, StatusCode.OK, "操作成功");
    }

    @Authority(AuthorityCode.USER)
    @DeleteMapping(value = "/{friendid}")
    public Result deleteByFriendid(@PathVariable String friendid){
        friendService.deleteByUseridAndFriendid(securityUtils.getCuurentUserid(), friendid);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
